/*
    Copyright (c) 2011-2012 Qualcomm Technologies, Inc.  All Rights Reserved.
    Qualcomm Technologies Proprietary and Confidential.
 */

package com.example.widgit;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.Camera.Parameters;
import android.os.PowerManager;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.Toast;
//TIANYURD zhangwp 20140121 add for CQWB00010199 begin
//TIANYURD zhangwp 20140121 add for CQWB00010199 end

public class LEDWidget extends AppWidgetProvider {
	// k-touch,liubzh. Modified for torch brightness. begin
	// public static final byte[] LIGHTE_ON = { '2', '5', '5' };
	public static final byte[] LIGHTE_ON = { '1', '2', '0' };
	// k-touch,liubzh. Modified for torch brightness. end
	public static final byte[] LIGHTE_OFF = { '0' };
	public static final byte[] LIGHT_TORCH = { '1' };
	public static final byte[] LIGHT_DEFAULT = { '0' };

	public final static String TAG = "LEDWidget";
	private static boolean mLightsOn = false;

	// LED light is on or off before pass PowerKey.
	private static boolean mLightsOnBeforePower = false;

	private static Parameters mCameraParas = null;

	private static PowerManager.WakeLock mWakeLock;

	private static boolean mIsLockAcquired = false;

	private final String broadCastString = "qualcomm.android.LEDFlashlight.appWidgetUpdate";
	private final String broadCastPowerKey = "qualcomm.android.LEDFlashlight.LEDUpdate";
	private final String broadCastKilled = "com.android.LEDFlashlight.processKilled";

	// LED node used in different chipsets
	private final static String MSM8226_FLASHLIGHT_BRIGHTNESS = "/sys/class/leds/torch-light/brightness";
	private final static String COMMON_FLASHLIGHT_BRIGHTNESS = "/sys/class/leds/flashlight/brightness";
	private final static String COMMON_FLASHLIGHT_MODE = "/sys/class/leds/flashlight/mode";
	private static boolean DBG = !false;

	// TIANYURD zhangwp 20140121 add for CQWB00010199 begin
	private static int mBatteryLevel = 100;
	private final static int BATTERY_LOW_LEVEL = 5;
	private static boolean mBatteryintentregist = false;

	// TIANYURD zhangwp 20140121 add for CQWB00010199 end

	/**
	 * used when remove a wiget
	 * */
	// @Override
	public void onDeleted(Context context, int[] appWidgetIds) {
		Log.v(TAG, "onDeleted");
		super.onDeleted(context, appWidgetIds);
	}

	/**
	 * used when the last widget is removed
	 * */
	@Override
	public void onDisabled(Context context) {
		Log.v(TAG, "onDisabled");
		super.onDisabled(context);
	}

	/**
	 * used when the widget is created first
	 * */
	@Override
	public void onEnabled(Context context) {
		Log.v(TAG, "onEnabled");
	}

	// TIANYURD zhangwp 20140121 add for CQWB00010199 begin
	private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {

		}
	};

	// TIANYURD zhangwp 20140121 add for CQWB00010199 end

	/**
	 * accept broadcast
	 * */
	@Override
	public void onReceive(Context context, Intent intent) {
		super.onReceive(context, intent);
		Log.d(TAG, "onReceive = ");
	}

	/**
	 * used when user action or the widget is placed on the home screen
	 * */
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager,
			int[] appWidgetIds) {
		Log.v(TAG, "onUpdate");

	}

}